"""Definition of the ad content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
from Products.ATContentTypes.content.newsitem import ATNewsItem,ATNewsItemSchema

# -*- Message Factory Imported Here -*-
from my315ok.xtinfocontent import xtinfocontentMessageFactory as _

from my315ok.xtinfocontent.interfaces import Iad,IadMark
from my315ok.xtinfocontent.config import PROJECTNAME

adSchema = ATNewsItemSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.StringField(
        'position',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.xtinfocontent.adposition",
        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"ad position"),
            description=_(u""),
        ),
        required=True,
    ),


    atapi.FileField(
        'swf',
#        primary=True,
        storage=atapi.AnnotationStorage(),
        widget=atapi.FileWidget(
            label=_(u"ad swf"),
            description=_(u"Add Flash object"),
        ),
        validators=('isNonEmptyFile'),
    ),


#    atapi.ImageField(
#        'image',
#        storage=atapi.AnnotationStorage(),
#        widget=atapi.ImageWidget(
#            label=_(u"ad image"),
#            description=_(u""),
#        ),
#        validators=('isNonEmptyFile'),
#    ),


    atapi.IntegerField(
        'maxclicks',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"max clicks"),
            description=_(u"Maximum number of clicks"),
        ),
        validators=('isInt'),
    ),


    atapi.IntegerField(
        'clickused',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"click used"),
            description=_(u"click used"),
        ),
        validators=('isInt'),
    ),


    atapi.StringField(
        'linkintern',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"intern link"),
            description=_(u"Intern link url"),
        ),
    ),


    atapi.StringField(
        'linkextern',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"extern link"),
            description=_(u"extern link url"),
        ),
        validators=('isURL'),
    ),


))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

adSchema['title'].storage = atapi.AnnotationStorage()
adSchema['description'].storage = atapi.AnnotationStorage()
adSchema['effectiveDate'].schemata = "default"
adSchema['text'].widget.visible = 0
adSchema['imageCaption'].widget.visible = 0


schemata.finalizeATCTSchema(adSchema, moveDiscussion=False)


class ad(ATNewsItem):
    """ad contenttype"""
    implements(Iad)

    meta_type = "ad"
    schema = adSchema
    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    position = atapi.ATFieldProperty('position')

    swf = atapi.ATFieldProperty('swf')

    image = atapi.ATFieldProperty('image')

    maxclicks = atapi.ATFieldProperty('maxclicks')

    clickused = atapi.ATFieldProperty('clickused')

    linkintern = atapi.ATFieldProperty('linkintern')

    linkextern = atapi.ATFieldProperty('linkextern')


atapi.registerType(ad, PROJECTNAME)
